Skip to content

fix: block SIGPIPE on the ADBC and pyo3 runtime threads - #510

Draft
vuanhphung wants to merge 1 commit into
fix/block-sigpipe-runtime-threadsfrom
fix/block-sigpipe-adbc-pyo3
Draft

vuanhphung wants to merge 1 commit into
fix/block-sigpipe-runtime-threadsfrom
fix/block-sigpipe-adbc-pyo3

Conversation

@vuanhphung

@vuanhphung vuanhphung commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Follow-up to #509, which blocks SIGPIPE on the kernel's C-ABI and telemetry runtime threads. Two other runtimes run kernel socket I/O on threads they own, and neither was hooked:

  • The ADBC driver's own runtime (RuntimeHandle::create). When a Go program loads the driver through a cgo driver manager, a SIGPIPE raised on one of its workers kills the process.
  • The pyo3 per-session runtime. Python ignores SIGPIPE by default, but an app that restores SIG_DFL, a common CLI idiom, is killed instead of getting EPIPE.

This PR re-exports the kernel's block_sigpipe_on_current_thread from the crate root as #[doc(hidden)]. That is the smallest surface the sibling crates can use through their existing path dependency. Both runtimes now pass it to on_thread_start, so it covers workers and blocking-pool threads. The pyo3 builder moves from Session.__new__ into KernelRuntime::build so a test can check the real runtime; it is otherwise unchanged. Caller-injected ADBC runtimes and napi (Node ignores SIGPIPE) are left alone.

How exposed each runtime is today depends on its TLS backend. pyo3 builds with tls-rustls, which writes TLS records with writev, so any write after a peer reset raises SIGPIPE. ADBC uses the default tls-native: tokio-native-tls has only poll_write (tokio-native-tls/src/lib.rs:149,205 @02c1aeb), so on Linux its TLS writes end in std's send(MSG_NOSIGNAL). ADBC is therefore exposed only through plain-HTTP writev today; the hook matches the C-ABI runtime and covers any later rustls build.

Depends on #509 and targets its branch, so the diff shows only this change. It will be retargeted to main after #509 merges.

Cross-driver state

Host State Notes
Go via an ADBC driver manager (cgo) Exposed on plain-HTTP writes → Fixed (this PR) TLS writes on tls-native builds already use MSG_NOSIGNAL (see above)
Python (pyo3) Session threads exposed if the app restores SIG_DFL → Fixed (this PR) CPython sets SIG_IGN by default (Modules/signalmodule.c:1913 @v3.13.0); databricks-sql-python has no SIGPIPE handling
Go (C ABI), ODBC Fixed by #509 —
Node.js (napi) Not exposed Node sets SIG_IGN (src/node.cc:544 @v22.11.0)
JDBC Not applicable Doesn't use the kernel

No other Databricks driver blocks SIGPIPE itself; this follows #509's thread-scoped mask.

Testing

  • New Linux-only tests, owned_runtime_threads_block_sigpipe (adbc) and session_runtime_threads_block_sigpipe (pyo3), build the real runtime (RuntimeHandle::create, KernelRuntime::build). Each runs a task on a worker and on a spawn_blocking thread and checks SIGPIPE's bit in SigBlk, after first asserting that the test thread doesn't block it. fix: block SIGPIPE on kernel runtime threads #509's helper is cfg(test) in the kernel crate, so each crate carries a ten-line copy. fix: block SIGPIPE on kernel runtime threads #509's end-to-end SIG_DFL test isn't duplicated.
  • No Rust toolchain was available locally, so CI is the build, lint and test gate. The build and test workflows only run for PRs into main, so CI ran on 3d8ed34 while this PR briefly targeted main. Every check passed, except macOS dSYM, which is cancelled at its timeout on every recent main push (e.g. run 45768020222). Highlights:
    • ADBC native + C ABI (toolchain 1.89): clippy -D warnings and 99 tests pass, including owned_runtime_threads_block_sigpipe; the dlopen smoke test passes.
    • The six PyO3 build + test jobs pass session_runtime_threads_block_sigpipe. Their no-network pytest tests build a real Session against a local HTTP server, which exercises the moved builder.
    • Formatting, Clippy, Unit + doc tests, tls-rustls, Windows linker PDB, and the live v0 E2E surface and v0 TLS (mitmproxy) jobs all pass.
  • The pyo3 live pytest tier skips here, as it does on main (21 passed, 37 skipped in both; e.g. main run 45768020141). The label-gated ADBC live suite wasn't run.
  • Performance is unaffected: the hook adds one pthread_sigmask call per runtime thread start and nothing on the request path.

Additional notes

  • Futures driven by block_on still run on the caller's thread, which keeps the host's mask. Hyper's connection tasks, which do the writes on established connections, run on the hooked workers.
  • pyo3_log runs Python logging handlers on the thread that emits the record. In an app that restored SIG_DFL, a handler on a session worker that writes to a closed pipe now gets BrokenPipeError instead of killing the process, the same effect fix: block SIGPIPE on kernel runtime threads #509 noted for C-ABI log callbacks. Apps that keep Python's default SIG_IGN see no change.
  • Adversarial review: pending.

This pull request and its description were written by Isaac.

Export the kernel's block_sigpipe_on_current_thread as a #[doc(hidden)]
crate-root item and hook it with on_thread_start on the ADBC driver-owned
runtime and the pyo3 per-session runtime, workers and blocking pools.
Caller-injected ADBC runtimes are left alone. Linux tests check that a
worker and a spawn_blocking thread of each runtime block SIGPIPE.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@vuanhphung
vuanhphung changed the base branch from main to fix/block-sigpipe-runtime-threads November 27, 2026 02:20

This branch was successfully deployed

1 active deployment
azure-prod — 3d8ed343 Deployed Nov 27, 2026 by vuanhphung via v0 E2E surface #1471
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant